package Exercises;/*
 *
 * @author 陈粒
 * @version 创建时间：2021/7/5 16:30
 */
/**
 * 练习题:求猴子大王
 * 15个猴子围成一圈选大王,依次1-7循环报数,报到7的猴子被淘汰,直到最后一只猴子称为大王,问:哪只猴子会成为大王?
 * 重点为创建一个boolean数组
 */
public class Monkey_King {
    public static void main(String[] args) {
        boolean[] monkey = new boolean[15];
        for (int i = 0; i < 15; i++) {
            monkey[i] = true;
        }
        int last_monkey = 15;
        int index = 0;
        int num = 0;
        while (last_monkey != 1) {
            if (monkey[index]) {
                num++;
                if (num == 7) {
                    monkey[index] = false;
                    last_monkey--;
                    num = 0;
                }
            }
            index++;
            if (index == 15) {
                index = 0;
            }
        }
        for (int j = 0; j < 15; j++) {
            if (monkey[j] == true) {
                System.out.println(j + 1);
            }
        }
    }
}
